#include<iostream>
using namespace std;
int main()
{

    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    int n,i,ans[10000],a[10000];
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    ans[0][0]=0;
    for(i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==0||j==0)
                ans[i][j]=0;
            else
            {
                if(a[i]>a[j])
                    ans[i][j]=ans[i-1][j-1]+1;
                if(a[i]<=a[j])
                    ans[i][j]=min(ans[i][j-1],ans[i-1][j]);
            }
        }
    cout<<ans[n][n];
    return 0;
}
